<!--
 * @Author: ChaiHongJun
 * @Date: 2021-04-06 21:18:37
 * @LastEditors: ChaiHongJun
 * @LastEditTime: 2021-05-01 15:33:45
 * @version: 
 * @Description:MV组件
-->
<template>
  <div class="load-more">
    <div class="mv-box">
      <ul class="mv-list">
        <li v-for="(mv, index) of mvs" :key="index" @click="getDetail(mv)">
          <div class="cover">
            <div class="image">
              <el-image
                :src="mv.cover + '?param=352y197'"
                :alt="mv.name"
              ></el-image>
            </div>
            <div class="count">
              <i class="arrow"></i>
              <span>{{ formatPlayCount(mv.playCount) }}</span>
            </div>
            <div class="action">
              <button title="播放" class="play flex-center">
                <i class="iconfont nicebofang1"></i>
              </button>
            </div>
            <div class="foot">
              <p>{{ mv.artists.name }}</p>
              <p>{{ formatDuration(mv.duration) }}</p>
            </div>
          </div>
          <div class="info">
            <h2 class="title ellipsis">{{ index + 1 }}-{{ mv.name }}</h2>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import { getScrollTop, getClientTop, getScrollHeight } from "@/utils/index.js";
import { formatPlayCount, formatDuration } from "@/utils/index.js";
export default {
  props: {
    mvs: {
      type: Array,
    },
  },
  data() {
    return {
      limit: 20, //评论数
    };
  },

  computed: {
    formatPlayCount() {
      return (number) => {
        return formatPlayCount(number);
      };
    },
    formatDuration() {
      return (number) => {
        return formatDuration(number);
      };
    },
  },
  mounted() {
    //判断页面滚动
    let _this = this;
    document.addEventListener(
      "scroll",
      function () {
        if (getScrollTop() + getClientTop() + 1 >= getScrollHeight()) {
          //当滑动到一定位置，触发加载更多事件
          _this.$emit("loadMore");
        }
      },
      true
    );
  },
  methods: {
    getDetail(mv) {
      //进入MV播放页
      this.$router.push({ name: "mvDetail", query: { id: mv.id } });
    },
  },
};
</script>
<style lang="stylus" scoped>
.mv-box {
  padding: 15px 0;

  .mv-list {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    margin: 0 -15px;

    li {
      padding: 0 15px 30px;
      flex: 0 0 25%;
      max-width: 25%;

      .cover {
        position: relative;
        z-index: 2;
        padding-top: 56%;
        border-radius: 2px;
        background-color: #000;

        .image {
          position: absolute;
          top: 0;
          left: 0;
          overflow: hidden;
          width: 100%;
          height: 100%;
          border-radius: 2px;
        }

        .count {
          position: absolute;
          right: 16px;
          top: 1px;
          height: 24px;
          padding-left: 9px;
          background: url('https://img.alicdn.com/tfs/TB1xEGRub9YBuNjy0FgXXcxcXXa-268-48.png') no-repeat 0; // img.alicdn.com/tfs/TB1xEGRub9YBuNjy0FgXXcxcXXa-268-48.png) no-repeat 0;
          background-size: cover;
          color: #fff;
          font-size: 12px;
          font-weight: 700;
          line-height: 24px;
          display: flex;
          align-items: center;
          justify-content: center;

          .arrow {
            display: block;
            width: 0;
            height: 0;
            border-style: solid;
            border-width: 4px 0 4px 6px;
            border-color: transparent transparent transparent #ffffff;
            margin-right: 5px;
          }

          &:after {
            content: '';
            position: absolute;
            right: -14px;
            top: 0;
            width: 14px;
            height: 24px;
            background: url('https://img.alicdn.com/tfs/TB1xEGRub9YBuNjy0FgXXcxcXXa-268-48.png') no-repeat 100%; // img.alicdn.com/tfs/TB1xEGRub9YBuNjy0FgXXcxcXXa-268-48.png) no-repeat 100%;
            background-size: cover;
          }
        }

        .action {
          display: none;
          position: absolute;
          top: 50%;
          left: 50%;
          -webkit-transform: translate(-50%, -50%);
          -ms-transform: translate(-50%, -50%);
          transform: translate(-50%, -50%);

          .play {
            width: 32px;
            height: 32px;
            padding: 0;
            border: none;
            border-radius: 50%;
            color: #fff;
            cursor: pointer;
            background-color: $color-theme;

            i {
              font-size: 12px;
            }
          }
        }

        .foot {
          width: 100%;
          height: 35px;
          background: rgba(0, 0, 0, 0.6);
          position: absolute;
          left: 0;
          bottom: 0;
          display: flex;
          align-items: center;
          justify-content: space-between;
          padding: 0 10px;

          p {
            color: #ffffff;
          }
        }

        &:hover {
          .action {
            display: flex;
          }
        }
      }

      .info {
        margin-top: 15px;

        .title {
          font-size: 14px;
          font-weight: 500;
          display: block;
          line-height: 1.3;
        }

        .author {
          margin-top: 5px;
          font-size: 12px;
          color: #999;
        }
      }

      &.live {
        .cover {
          .foot {
            background: rgba(250, 40, 0, 0.75);
          }
        }
      }
    }
  }
}
</style>